home *** CD-ROM | disk | FTP | other *** search
- Path: ccshst05.uoguelph.ca!ccshst01!thay
- From: thay@uoguelph.ca (Toby K Hay)
- Newsgroups: comp.lang.c
- Subject: Re: beginner needs help about langtons's ant
- Date: 21 Apr 1996 00:53:09 GMT
- Organization: University of Guelph
- Message-ID: <4lc0tl$ibl@ccshst05.uoguelph.ca>
- References: <4lbrsi$4o@usc.edu>
- NNTP-Posting-Host: ccshst01.uoguelph.ca
- X-Newsreader: TIN [version 1.2 PL2]
-
- Zahir Yilmaz Alpaslan (alpaslan) wrote:
- : I am trying to implement langton's ant in c.
- snip
- : When I tried to run this program in unix environment it gave a segmentation
- : fault, where did I go wrong?
-
- : char a[100][100];
- snip
- : int i,j;
- : for(i=0;i<=100;i++);
- : for(j=0;j<=100;j++);
- snip
-
- You get a segmentation fault by trying to access memory not allocated to
- your program. An obvious error of this type is that you declare array
- a[100][100] which will have index values from 0 to 99, but use i and j
- with values from 0 to 100 to access it. Try: for (i=0;i<100;i++) etc
- instead. As I look at your code above I see that the for statements each
- have a semicolon after them - an error which will prevent them iterating
- the block of code that follows them as you intended. You may need to do
- a little debugging yet.
- Toby Hay thay@uoguelph.ca
-